package repository.jooq.generated;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.jooq.util.GenerationTool;
import org.jooq.util.jaxb.*;

public class TryOne
{
	private static void main2(String[] args) throws Exception
	{
		Class.forName("org.postgresql.Driver");

		// STEP 3: Open a connection
		System.out.println("Connecting to database...");
		Connection conn = DriverManager.getConnection(
				"jdbc:postgresql://localhost:5432/cook-with-granny",
				"postgres", "postgres");

		System.out.println("Creating statement...");
		Statement stmt = conn.createStatement();
		String sql;
		sql = "select * from recipes";
		ResultSet rs = stmt.executeQuery(sql);
		while (rs.next())
		{
			System.out.println(rs.getString(1));
		}
	}

	public static void main(String[] args) throws Exception
	{
		Configuration configuration = new Configuration()
				.withJdbc(
						new Jdbc().withDriver("org.postgresql.Driver")
								.withUrl("jdbc:postgresql:cook-with-granny")
								.withUser("postgres").withPassword("postgres"))
				.withGenerator(
						new Generator()
								.withName("org.jooq.util.DefaultGenerator")
								.withDatabase(
										new Database()
												.withName(
														"org.jooq.util.postgres.PostgresDatabase")
												.withIncludes(".*")
												.withExcludes("")
												.withInputSchema("public"))
								.withTarget(
										new Target()
												.withPackageName(
														"org.jooq.util.maven.example")
												.withDirectory(
														"src/")));//"target/generated-sources/jooq")));

		GenerationTool.main(configuration);
	}
}
